import { defineStore } from "pinia";
import { ref } from "vue";
import { RouteRecordRaw } from "vue-router";
import { getRoutes } from "@/utils/router";

export const useRouterStore = defineStore("router", () => {
  const constantRoutes = ref<RouteRecordRaw[]>([]);
  const authRoutes = ref<RouteRecordRaw[]>([]);
  const excludeCacheRoutes = ref<RouteRecordRaw[]>([]);

  function setConstantRoutes(value: RouteRecordRaw[]) {
    constantRoutes.value = value;
  }

  function setAuthRoutes(value: RouteRecordRaw[]) {
    authRoutes.value = value;
  }

  function setExcludeCacheRoutes(value: RouteRecordRaw[]) {
    excludeCacheRoutes.value = value;
  }

  function initRoutes() {
    const { authRoutes, constantRoutes } = getRoutes();
    setAuthRoutes(authRoutes);
    setConstantRoutes(constantRoutes);
  }

  return {
    constantRoutes,
    authRoutes,
    setAuthRoutes,
    setConstantRoutes,
    excludeCacheRoutes,
    setExcludeCacheRoutes,
    initRoutes
  };
});
